package com.jiandian.service.impl;

import com.jiandian.dao.ActivememberMapper;
import com.jiandian.entity.Activemember;
import com.jiandian.page.PageInfo;
import com.jiandian.service.ActivememberService;
import com.jiandian.util.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

/**
 * 网吧用户
 *
 * @author houqi Fu
 * @date 2018/12/16
 */
@Service
@Transactional
public class ActivememberServiceImpl implements ActivememberService {

    private static final Logger logger = LoggerFactory.getLogger(ActivememberServiceImpl.class);

    @Autowired
    private ActivememberMapper mapper;


    // @Override
    // public Activemember add(Activemember record) {
    //
    //     initBasicValue(record);
    //
    //     int result = mapper.insert(record);
    //     if (result > 0) {
    //         return record;
    //     }
    //     return null;
    // }

    // @Override
    // public Activemember update(Activemember record) {
    //     // Long id = record.getId();
    //     // if (id == null) {
    //     //     return null;
    //     // }
    //     // Activemember dbActivemember = mapper.selectByPrimaryKey(id);
    //     // if (dbActivemember == null) {
    //     //     return null;
    //     // }
    //     // BeanUtils.copyProperties(record, dbActivemember);
    //     // int result = mapper.updateByPrimaryKey(dbActivemember);
    //     // if (result > 0){
    //     //     return dbActivemember;
    //     // }
    //     return null;
    // }

    @Override
    public Activemember findById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Activemember> findAll(PageInfo pageInfo) {
        return mapper.selectAll(pageInfo);
    }

    @Override
    public int selectCount(PageInfo pageInfo) {
        return mapper.selectCount(pageInfo);
    }

    // @Override
    // public int batchInsert(List<Activemember> list) {
    //     for (Activemember bean : list) {
    //         initBasicValue(bean);
    //     }
    //     return mapper.batchInsert(list);
    // }

    @Override
    public List<Activemember> batchQueryByIds(List<Long> ids) {
        return mapper.batchQueryByIds(ids);
    }

    @Override
    public Activemember findByMachineNumber(String machineNumber) {

        return mapper.findByMachineNumber(machineNumber);
    }

    // @Override
    // public int delete(Long id) {
    //     return mapper.deleteByPrimaryKey(id);
    // }
    //
    // @Override
    // public int delete(Activemember record) {
    //     return 0;
    // }

    // @Override
    // public int batchDeleteById(List<Long> ids) {
    //     if (CollectionUtils.isNotEmpty(ids)) {
    //         return mapper.batchDeleteById(ids);
    //     }
    //     return 0;
    // }

    private void initBasicValue(Activemember record){
        // Timestamp now = new Timestamp(System.currentTimeMillis());
        // record.setGmtCreate(now);
        // record.setGmtModified(now);
    }
}
